package transport;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class DelegatingVehicleTracker {

	public final ConcurrentMap<String, ImmutablePoint> locations;
	public final Map<String, ImmutablePoint> unmodifiableMap;

	public DelegatingVehicleTracker(Map<String, ImmutablePoint> data) {
		locations = new ConcurrentHashMap<String, ImmutablePoint>(data);
		unmodifiableMap = Collections.unmodifiableMap(locations);
	}

	public Map<String, ImmutablePoint> getLocation(String name) {
		return unmodifiableMap;
	}

	public Map<String, ImmutablePoint> getLocationAsStatic(String name) {
		return Collections.unmodifiableMap(new HashMap<String, ImmutablePoint>(
				locations));
	}

	public void setLocation(String name, ImmutablePoint point) {
		if (locations.replace(name, point) == null)
			throw new IllegalArgumentException();
	}

	public Map<String, ImmutablePoint> getLocations() {
		return unmodifiableMap;
	}

}
